
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI问答助手</title>
<!--    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>-->
<!--    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>-->
    <script src="js/vue-2.4.0.js"></script>
    <script src="js/axios.min.js"></script>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            margin: 0;
            padding: 20px;
            min-height: 100vh;
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
            background: white;
            border-radius: 10px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            padding: 30px;
        }
        h1 {
            color: #4a6baf;
            text-align: center;
            margin-bottom: 30px;
        }
        .input-group {
            display: flex;
            margin-bottom: 20px;
        }
        input {
            flex: 1;
            padding: 12px 15px;
            border: 1px solid #ddd;
            border-radius: 5px 0 0 5px;
            font-size: 16px;
            outline: none;
            transition: border 0.3s;
        }
        input:focus {
            border-color: #4a6baf;
        }
        button {
            background: #4a6baf;
            color: white;
            border: none;
            padding: 12px 20px;
            border-radius: 0 5px 5px 0;
            cursor: pointer;
            font-size: 16px;
            transition: background 0.3s;
        }
        button:hover {
            background: #3a5a9f;
        }
        button:disabled {
            background: #cccccc;
            cursor: not-allowed;
        }
        .output-container {
            display: flex;
            gap: 20px;
            margin-top: 20px;
        }
        .output-box {
            flex: 1;
            border: 1px solid #ddd;
            border-radius: 5px;
            padding: 15px;
            min-height: 200px;
            background: #f9f9f9;
        }
        .output-title {
            font-weight: bold;
            margin-bottom: 10px;
            color: #4a6baf;
        }
        .loading {
            text-align: center;
            padding: 20px;
            color: #4a6baf;
        }
        .spinner {
            border: 4px solid rgba(0, 0, 0, 0.1);
            border-radius: 50%;
            border-top: 4px solid #4a6baf;
            width: 30px;
            height: 30px;
            animation: spin 1s linear infinite;
            margin: 0 auto 10px;
        }
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
</head>
<body>
<div id="app">
    <div class="container">
        <h1>AI问答助手</h1>
        <div class="input-group">
            <input
                    type="text"
                    v-model="question"
                    placeholder="请输入您的问题..."
                    @keyup.enter="submitQuestion"
            >
            <button
                    @click="submitQuestion"
                    :disabled="isLoading || !question.trim()"
            >
                提问
            </button>
        </div>

        <div v-if="isLoading" class="loading">
            <div class="spinner"></div>
            <p>AI正在思考中...</p>
        </div>

        <div class="output-container" v-if="response">
            <div class="output-box">
                <div class="output-title">AI回答</div>
                <div>{{ response.answer }}</div>
            </div>
            <div class="output-box">
                <div class="output-title">私有数据</div>
                <div>{{ response.strategies }}</div>
            </div>
        </div>
    </div>
</div>

<script>
    new Vue({
        el: '#app',
        data: {
            question: '',
            isLoading: false,
            response: null
        },
        methods: {
            submitQuestion() {
                if (!this.question.trim()) return;

                this.isLoading = true;
                this.response = { answer: '', strategies: '' };

                axios.get('http://localhost:8080/chat', {
                    params:{
                        question: this.question
                    }
                })
                    .then(response => {
                        this.response = {
                            answer: response.data.answer ||'暂无回答',
                            strategies: response.data.strategies ||'暂无私有数据'
                        };
                    })
                    .catch(error => {
                        console.error('请求出错:', error);
                        this.response.answer = '请求出错，请稍后再试';
                    })
                    .finally(() => {
                        this.isLoading = false;
                    });
            }
        }
    });
</script>
</body>
</html>
